/*
 * Task.cpp
 *
 *  Created on: Jan 13, 2010
 *      Author: artur
 */

#include <sys/sched/task/Task.h>
#include <mem/MemFactory.h>
#include <Console.h>

extern kernel::Console cout;

namespace kernel
{
  namespace sys
  {
    namespace sched
    {
      namespace task
      {

        void
        Task::_init(void)
        {
          // this->vmap.pgd = 0;
        }

        Task::Task()
        {
          OUTDEBUG("[ Task ]");
          _init();
        }

        Task::Task(Task::task_entry_t e, LEVEL l) :
          entry(e), pl(l)
        {

          OUTDEBUG("[ Task ]");
          _init();

          /* TODO IMPORTANT!! stack_top must be aligned!!!! */
          /* FIXME  IMPORTANT!! stack_top must be aligned!!!! */
          /* TODO Free newobj on error!! */
          tsk_context.k_stack_top = (vaddr_t) new char[TASK_STACK_SIZE];
          if (tsk_context.k_stack_top)
            {
              tsk_context.k_stack_top += TASK_STACK_SIZE;
              // FIXME dummy Task STACK! align (16byte)
              tsk_context.k_stack_top &= ~(0x10 - 1);
            }

          tsk_context.u_stack_top = (vaddr_t) new char[TASK_STACK_SIZE];
          if (tsk_context.u_stack_top)
            {
              tsk_context.u_stack_top += TASK_STACK_SIZE;
              // FIXME dummy align (16byte)
              tsk_context.u_stack_top &= ~(0x10 - 1);
            }

        }

        Task::~Task()
        {
        }

        bool
        Task::operator==(const Task &t)
        {
          return false;
        }

        bool
        Task::operator!=(const Task &t)
        {
          return !(*this == t);
        }

      }
    }
  }
}
